<?php
//Needed for connectDB
require("dbFunctions.php");

/**
 * Removes all associations between a container and its direct descendents
 * If the provided ID is part of a package, but not the top level, then
 * remove just that item from the package.
 * 
 * Author: Steve Gennaoui
 * Date: 11/07/2012
 */

//Get the parameters
$qr_code = $_REQUEST['qr_code'];

if( is_null($qr_code) )
	die("No QR Code provided.");
if( !idIsValid($qr_code,"QR_Code") )
	die("The provided QR Code is invalid.");
if( !isPartOfPackage($qr_code) )
	die("The provided QR Code is not currently part of a resource package.");
$dbh = connectDB();
if( !isTopLevel($qr_code) )
{
	$query = "DELETE FROM Resource_Packages WHERE contained_qr_code=:contained";
	$stmt = $dbh->prepare($query);
	$stmt->bindParam(':contained',$qr_code);
	$stmt->execute();
}
else
{
	$query = "DELETE FROM Resource_Packages WHERE container_qr_code=:container";
	$stmt = $dbh->prepare($query);
	$stmt->bindParam(':container',$qr_code);
	$stmt->execute();
}
$stmt = null;
$dbh = null;

?>
